home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / pcl4w13.zip / LOGIN.C < prev    next >
Text File  |  1996-07-14  |  14KB  |  409 lines

  1. /*
  2. **                    --- login.c ---
  3. **
  4. **  EXAMPLE CODE: Very login terminal emulator, capbale of logging onto a BBS.
  5. **
  6. **  This example program (not the PCL4W library) is donated to
  7. **  the Public Domain by MarshallSoft Computing, Inc. It is
  8. **  provided as an example of the use of the PCL4W.
  9. **
  10. */
  11.  
  12. #define USECOMM
  13.  
  14. #include "windows.h"
  15. #include "stdio.h"
  16. #include "pcl4w.h"
  17. #include "sioerror.h"
  18. #include "ascii.h"
  19. #include "login.h"
  20. #include "message.h"
  21. #include "line.h"
  22. #include "paint.h"
  23. #include "about.h"
  24. #include "mio.h"
  25.  
  26. #define ONE_SEC 1000L
  27. #define ULONG unsigned long
  28.  
  29. #define Handshake_1  11
  30. #define Handshake_2  12
  31. #define Handshake_3  13
  32. #define Dial_1  21
  33. #define Dial_2  22
  34. #define Dial_3  23
  35.  
  36. /* public globals */
  37.  
  38. HWND hMainWnd;            /* main window handle */
  39. int OnLineFlag = FALSE;   /* TRUE: online */
  40. int FatalFlag = FALSE;    /* TRUE: fatal error */
  41.  
  42. /* private globals */
  43.  
  44. static HMENU hMenu;
  45. static HANDLE hInstance;
  46. static int ThePort = COM1;
  47. static int TheBaud = Baud19200;
  48. static int WinWidth = 8 * NCOLS;
  49. static int WinHeight = 12 * NROWS + 48;
  50. static long BaudRateList[10]
  51.        = {300L,600L,1200L,2400L,4800L,9600L,19200L,38400L,57600L,115200L};
  52. static int mioState = 0;
  53. static char Temp[1024];
  54.  
  55. /* miscellaneous functions */
  56.  
  57. void ErrorCheck(int);
  58. int PutGet(char *,char *,ULONG);
  59.  
  60. int PASCAL WinMain(HANDLE hInst,HANDLE hPrevInstance,
  61.                    LPSTR lpCmdLine,int nCmdShow)
  62. {WNDCLASS  wc;
  63.  MSG msg;
  64.  BOOL Result;
  65.  if(!hPrevInstance)
  66.    {/* register main window class */
  67.     wc.style = CS_HREDRAW | CS_VREDRAW;
  68.     wc.lpfnWndProc = MainWndProc;
  69.     wc.cbClsExtra = 0;
  70.     wc.cbWndExtra = 0;
  71.     wc.hInstance = hInst;
  72.     wc.hIcon = LoadIcon(hInst, "LoginIcon");
  73.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  74.     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  75.     wc.lpszMenuName =  "LoginMenu";
  76.     wc.lpszClassName = "LoginWClass";
  77.     Result = RegisterClass(&wc);
  78.     if(!Result) return FALSE;
  79.    }
  80.  
  81.  /* create main window */
  82.  hInstance = hInst;
  83.  hMainWnd = CreateWindow(
  84.         "LoginWClass",   "LOGIN",       WS_OVERLAPPEDWINDOW,
  85.         CW_USEDEFAULT,    CW_USEDEFAULT,
  86.         WinWidth,         WinHeight,
  87.         NULL,             NULL,
  88.         hInstance,        NULL);
  89.  ShowWindow(hMainWnd, nCmdShow);
  90.  UpdateWindow(hMainWnd);
  91.  hMenu = GetMenu(hMainWnd);
  92.  
  93.  /* window control loop */
  94.  
  95.  while(GetMessage(&msg,NULL,NULL,NULL))
  96.    {
  97.     TranslateMessage(&msg);
  98.     DispatchMessage(&msg);
  99.    }
  100.  return (msg.wParam);
  101. } /* end WinMain */
  102.  
  103. long FAR PASCAL MainWndProc(HWND hWindow,UINT message,WPARAM wParam,LPARAM lParam)
  104. {
  105.  UINT idTimer;
  106.  HDC hDC;
  107.  PAINTSTRUCT ps;
  108.  int i, rc;
  109.  int TheChar;
  110.  int Count;
  111.  int Code;
  112.  static FARPROC lpProcAbout;
  113.  
  114.  
  115.  hMainWnd = hWindow;
  116.  switch (message)
  117.     {
  118.      case WM_COMMAND:
  119.          switch(wParam)
  120.            {case MSG_ABOUT:
  121.               DialogBox(hInstance,"AboutBox",hMainWnd,lpProcAbout);
  122.               break;
  123.  
  124.             case MSG_BREAK:
  125.               mioBreak(ThePort);
  126.               EnableMenuItem(hMenu,MSG_BREAK,MF_BYCOMMAND|MF_GRAYED);
  127.               mioState = 0;
  128.               break;
  129.  
  130.             case MSG_HANDSHAKE:
  131.               if(!OnLineFlag) DisplayLine("Must be online!");
  132.               else
  133.                 {mioState = Handshake_1;
  134.                  EnableMenuItem(hMenu,MSG_BREAK,MF_BYCOMMAND|MF_ENABLED);
  135.                 }
  136.               break;
  137.  
  138.             case MSG_DIAL:
  139.               if(!OnLineFlag) DisplayLine("Must be online!");
  140.               else
  141.                 {mioState = Dial_1;
  142.                  EnableMenuItem(hMenu,MSG_BREAK,MF_BYCOMMAND|MF_ENABLED);
  143.                 }
  144.               break;
  145.  
  146.             case MSG_DEBUG:
  147.               break;
  148.  
  149.             case MSG_ONLINE:
  150.               if(OnLineFlag) break;
  151.               else
  152.                 {/* try to go on-line */
  153.                  if(GoOnLine(ThePort,TheBaud,Size1024,Size1024))
  154.                    {/* we're online */
  155.                     OnLineFlag = TRUE;
  156.                     sprintf(Temp,"LOGIN: COM%d online at %ld baud",
  157.                        1+ThePort,BaudRateList[TheBaud]);
  158.                     SetWindowText(hMainWnd,Temp);
  159.                     CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_UNCHECKED);
  160.                     CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_CHECKED);
  161.                     for(i=MSG_COM1;i<=MSG_COM4;i++)
  162.                       EnableMenuItem(hMenu,i,MF_BYCOMMAND|MF_GRAYED);
  163.                     for(i=MSG_300;i<=MSG_115200;i++)
  164.                       EnableMenuItem(hMenu,i,MF_BYCOMMAND|MF_GRAYED);
  165.                    }
  166.                 }
  167.               break;
  168.  
  169.             case MSG_OFFLINE:
  170.               if(!OnLineFlag) break;
  171.               GoOffLine(ThePort);
  172.               OnLineFlag = FALSE;
  173.               SetWindowText(hMainWnd,"LOGIN: Offline");
  174.               CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_UNCHECKED);
  175.               CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_CHECKED);
  176.               for(i=MSG_COM1;i<=MSG_COM4;i++)
  177.                 EnableMenuItem(hMenu,i,MF_BYCOMMAND|MF_ENABLED);
  178.               for(i=MSG_300;i<=MSG_115200;i++)
  179.                 EnableMenuItem(hMenu,i,MF_BYCOMMAND|MF_ENABLED);
  180.               break;
  181.  
  182.             case MSG_EXIT:
  183.               DestroyWindow(hMainWnd);
  184.               break;
  185.  
  186.             case MSG_COM1:
  187.               CheckMenuItem(hMenu,MSG_COM1+ThePort,MF_BYCOMMAND | MF_UNCHECKED);
  188.               ThePort = COM1;
  189.               CheckMenuItem(hMenu,MSG_COM1,MF_BYCOMMAND | MF_CHECKED);
  190.               break;
  191.  
  192.             case MSG_COM2:
  193.               CheckMenuItem(hMenu,MSG_COM1+ThePort,MF_BYCOMMAND | MF_UNCHECKED);
  194.               ThePort = COM2;
  195.               CheckMenuItem(hMenu,MSG_COM2,MF_BYCOMMAND | MF_CHECKED);
  196.               break;
  197.  
  198.             case MSG_COM3:
  199.               CheckMenuItem(hMenu,MSG_COM1+ThePort,MF_BYCOMMAND | MF_UNCHECKED);
  200.               ThePort = COM3;
  201.               CheckMenuItem(hMenu,MSG_COM3,MF_BYCOMMAND | MF_CHECKED);
  202.               break;
  203.  
  204.             case MSG_COM4:
  205.               CheckMenuItem(hMenu,MSG_COM1+ThePort,MF_BYCOMMAND | MF_UNCHECKED);
  206.               ThePort = COM4;
  207.               CheckMenuItem(hMenu,MSG_COM4,MF_BYCOMMAND | MF_CHECKED);
  208.               break;
  209.  
  210.             case MSG_300:
  211.               CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
  212.               TheBaud = Baud300;
  213.               CheckMenuItem(hMenu,MSG_300,MF_BYCOMMAND | MF_CHECKED);
  214.               break;
  215.  
  216.             case MSG_1200:
  217.               CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
  218.               TheBaud = Baud1200;
  219.               CheckMenuItem(hMenu,MSG_1200,MF_BYCOMMAND | MF_CHECKED);
  220.               break;
  221.  
  222.             case MSG_2400:
  223.               CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
  224.               TheBaud = Baud2400;
  225.               CheckMenuItem(hMenu,MSG_2400,MF_BYCOMMAND | MF_CHECKED);
  226.               break;
  227.  
  228.             case MSG_4800:
  229.               CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
  230.               TheBaud = Baud4800;
  231.               CheckMenuItem(hMenu,MSG_4800,MF_BYCOMMAND | MF_CHECKED);
  232.               break;
  233.  
  234.             case MSG_9600:
  235.               CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
  236.               TheBaud = Baud9600;
  237.               CheckMenuItem(hMenu,MSG_9600,MF_BYCOMMAND | MF_CHECKED);
  238.               break;
  239.  
  240.             case MSG_19200:
  241.               CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
  242.               TheBaud = Baud19200;
  243.               CheckMenuItem(hMenu,MSG_19200,MF_BYCOMMAND | MF_CHECKED);
  244.               break;
  245.  
  246.             case MSG_38400:
  247.               CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
  248.               TheBaud = Baud38400;
  249.               CheckMenuItem(hMenu,MSG_38400,MF_BYCOMMAND | MF_CHECKED);
  250.               break;
  251.  
  252.             case MSG_57600:
  253.               CheckMenuItem(hMenu,MSG_300+TheBaud,MF_BYCOMMAND | MF_UNCHECKED);
  254.